#ifndef BIGQ_H
#define BIGQ_H
#include <pthread.h>
#include <iostream>
#include <queue>
#include <vector>
#include "Pipe.h"
#include "File.h"
#include "Record.h"

using namespace std;

class BigQ {
    private:
    char* filename;
    File midFile;
    File finalFile;
    public:

	BigQ (Pipe &in, Pipe &out, OrderMaker &sortorder, int runlen);
	~BigQ ();
};

class BigQInfo{
public:
    Pipe *in;
    Pipe *out;
    OrderMaker order;
    int runLength;
    File midFile;
};

class Comparator
{
private:
    OrderMaker sortorder;
    bool isPq;

public:
    Comparator(OrderMaker sortorder, bool isPq)
    {
        sortorder.Copy(this->sortorder);
        this->isPq = isPq;
    }

    bool operator () (Record* left, Record* right)
    {
        ComparisonEngine compEng;
        if(!isPq) return compEng.Compare(left, right, &sortorder)<0;
        else return compEng.Compare(left, right, &sortorder)>0;
    }
};

#endif
